package com.example.todolist;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MyAdapter2 extends ArrayAdapter {
    public MyAdapter2(@NonNull Context context, int resource, ArrayList<HashMap<String,String>> list) {
        super(context, resource,list);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View itemView = convertView;
        if (itemView==null){
            itemView= LayoutInflater.from(getContext()).inflate(R.layout.list_item2,parent,false);
        }
        Map<String,String> map= (Map<String, String>) getItem(position);
        TextView title=itemView.findViewById(R.id.title);
        TextView detail=itemView.findViewById(R.id.detail);
        TextView month=itemView.findViewById(R.id.month);
        TextView day=itemView.findViewById(R.id.day);


        Log.i("myadapter", "title"+map.get("title")+map.get("detail"));
        title.setText(map.get("title"));
        detail.setText(map.get("detail"));
        String m=map.get("ddl").substring(6,7);
        String d=map.get("ddl").substring(8);

        if(m.equals("1")){
            m="Jan";
        }else if(m.equals("2")){
            m="Feb";
        }else if(m.equals("3")){
            m="Mar";
        }else if(m.equals("4")){
            m="Apr";
        }else if(m.equals("5")){
            m="May";
        }else if(m.equals("6")){
            m="Jun";
        }else if(m.equals("7")){
            m="Jul";
        }else if(m.equals("8")){
            m="Aug";
        }else if(m.equals("9")){
            m="Sept";
        }else if(m.equals("10")){
            m="Oct";
        }else if(m.equals("11")){
            m="Nov";
        }else{
            m="Dec";
        }

        month.setText(m);
        day.setText(d);

        return  itemView;

    }
}
